Skip to content

Conversation

tiif
Copy link
Member

@tiif tiif commented Aug 8, 2025

Now that we have #[unstable_feature_bound], we can remove UnsizedConstParamTy that was meant to be an unstable impl of stable type and ConstParamTy_ trait.

r? @BoxyUwU

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Aug 8, 2025
@rust-log-analyzer

This comment has been minimized.

fmease added a commit to fmease/rust that referenced this pull request Aug 11, 2025
Support using #[unstable_feature_bound] on trait

This is needed to unblock rust-lang#145095

r? `@BoxyUwU`
fmease added a commit to fmease/rust that referenced this pull request Aug 12, 2025
Support using #[unstable_feature_bound] on trait

This is needed to unblock rust-lang#145095

r? ``@BoxyUwU``
fmease added a commit to fmease/rust that referenced this pull request Aug 12, 2025
Support using #[unstable_feature_bound] on trait

This is needed to unblock rust-lang#145095

r? ```@BoxyUwU```
fmease added a commit to fmease/rust that referenced this pull request Aug 12, 2025
Support using #[unstable_feature_bound] on trait

This is needed to unblock rust-lang#145095

r? ````@BoxyUwU````
fmease added a commit to fmease/rust that referenced this pull request Aug 12, 2025
Support using #[unstable_feature_bound] on trait

This is needed to unblock rust-lang#145095

r? `````@BoxyUwU`````
Zalathar added a commit to Zalathar/rust that referenced this pull request Aug 12, 2025
Support using #[unstable_feature_bound] on trait

This is needed to unblock rust-lang#145095

r? ``````@BoxyUwU``````
Zalathar added a commit to Zalathar/rust that referenced this pull request Aug 12, 2025
Support using #[unstable_feature_bound] on trait

This is needed to unblock rust-lang#145095

r? ```````@BoxyUwU```````
rust-timer added a commit that referenced this pull request Aug 12, 2025
Rollup merge of #145251 - tiif:support_trait, r=BoxyUwU

Support using #[unstable_feature_bound] on trait

This is needed to unblock #145095

r? ```````@BoxyUwU```````
github-actions bot pushed a commit to rust-lang/miri that referenced this pull request Aug 13, 2025
Support using #[unstable_feature_bound] on trait

This is needed to unblock rust-lang/rust#145095

r? ```````@BoxyUwU```````
github-actions bot pushed a commit to rust-lang/rustc-dev-guide that referenced this pull request Aug 18, 2025
Support using #[unstable_feature_bound] on trait

This is needed to unblock rust-lang/rust#145095

r? ```````@BoxyUwU```````
@rust-cloud-vms rust-cloud-vms bot force-pushed the unstable_const_param branch from a4bd0a8 to 262cf11 Compare August 18, 2025 15:00
Ok(())
})
} else if tcx.features().adt_const_params() {
if tcx.features().adt_const_params() || tcx.features().unsized_const_params() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should make unsized_const_params no longer be a lang feature. you can do this by removing its entry from unstable.rs

@tiif
Copy link
Member Author

tiif commented Aug 22, 2025

Currently all tests in tests/ui passed locally, but some test change feels suspicious, will take a closer look soon 🤔

@bors
Copy link
Collaborator

bors commented Aug 23, 2025

☔ The latest upstream changes (presumably #145773) made this pull request unmergeable. Please resolve the merge conflicts.

Comment on lines 822 to 824
if tcx.features().adt_const_params()
|| tcx.features().enabled(sym::unsized_const_params)
{
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It turns out that we need to have this change in order for the test here not to request for adt_const_params to be enabled.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that test should just enable adt_const_params

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

weird, why do we no longer emit error for this?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Foo implements ConstParamTy with no unstable_feature_bound so is useable by all downstream crates. This is fine I think

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a diagnostic regression here, it'd be nice to keep the help message.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Diagnostic is a bit chatty here, we already have the same diagnostic above, it'd be nice to only say it once.

Copy link
Member Author

@tiif tiif Sep 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suspect this happen because we have both #[unstable] and #[unstable_feature_bound] on the trait, and they emit two errors separately. I think I will just leave this as it is and write a test later.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test is in https://github.com/rust-lang/rust/pull/146401/files, I think we can leave this as it is, and improve the diagnostic in another PR.

@@ -101,7 +102,8 @@ pub fn type_allowed_to_implement_const_param_ty<'tcx>(
lang_item: LangItem,
parent_cause: ObligationCause<'tcx>,
) -> Result<(), ConstParamTyImplementationError<'tcx>> {
assert_matches!(lang_item, LangItem::ConstParamTy | LangItem::UnsizedConstParamTy);
assert_matches!(lang_item, LangItem::ConstParamTy);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need to accept a lang_item argument if it can only ever be one thing. just replace all uses of lang_item with LangItem::ConstParamTy

@@ -45,17 +45,11 @@ macro_rules! tuple_impls {
maybe_tuple_doc! {
$($T)+ @
#[unstable(feature = "adt_const_params", issue = "95174")]
#[unstable_feature_bound(adt_const_params)]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#[unstable_feature_bound(adt_const_params)]
#[unstable_feature_bound(unsized_const_params)]

dont want this impl insta-stable when we stabilize adt const params. its not really "unsized" but right now its the only other feature gate we can put impls under 😅

I expect we'll wind up with a bunch of different feature gates for "support X

Comment on lines 822 to 824
if tcx.features().adt_const_params()
|| tcx.features().enabled(sym::unsized_const_params)
{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that test should just enable adt_const_params

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Foo implements ConstParamTy with no unstable_feature_bound so is useable by all downstream crates. This is fine I think

@@ -142,7 +139,7 @@ fn visit_implementation_of_const_param_ty(
checker: &Checker<'_>,
kind: LangItem,
) -> Result<(), ErrorGuaranteed> {
assert_matches!(kind, LangItem::ConstParamTy | LangItem::UnsizedConstParamTy);
assert_matches!(kind, LangItem::ConstParamTy);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

u can remove the kind parameter, no need to accept an argument that can only be one value

@@ -5,14 +5,6 @@ LL | struct Foo<const NAME: &'static str>;
| ^^^^^^^^^^^^
|
= note: the only supported types are integers, `bool`, and `char`
help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types
Copy link
Member

@BoxyUwU BoxyUwU Sep 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

driveby: can you change this test to use a const generic parameter that would actually be supported under adt_const_params. e.g. struct Foo<const N: Bar>; struct Bar(u8);

parent_cause.clone(),
param_env,
ty::ClauseKind::UnstableFeature(sym::unsized_const_params),
))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe the diagnostic regression where we lost the help: enable this feature is caused by the fact that type_allowed_to_implement_const_param_ty no longer returns a special error for when its not allowed because of a unsized_const_params only type.

calling ocx.select_where_possible here and returning ConstParamTyImplementationError::UnsizedConstParamsFeatureRequired if there were any errors should fix that

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah. needs to be ocx.select_all_or_error actually. i forgot that unstable feature bounds never return NoSolution. You only register the bound here, you dont actually try and prove it and then return a custom failure reason which is what will bring back all the "help" messages

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

amazing, this works!

@@ -1,27 +1,19 @@
warning: the feature `unsized_const_params` is incomplete and may not be safe to use and/or cause compiler crashes
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah hmm :(

I kinda forgot that switching to a library feature would mean we no longer consider feature(unsized_const_params) to be incomplete 🤔 Do you think you could re-add unsized_const_params as a langauge feature just so that we continue getting these warnings? It shouldn't actually be used anywhere in the compiler, I just want people to get pushed away from actually using this for now lol

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I brought it back now. Initially I was thinking if there is any way to have similar error message for libs feature, but I didn't find anything. 🤔

Comment on lines +1 to +10
error[E0741]: `Bar` must implement `ConstParamTy` to be used as the type of a const generic parameter
--> $DIR/feature-gate-unsized-const-params.rs:5:21
|
LL | struct Foo<const N: [u8]>;
| ^^^^
LL | struct Foo<const N: Bar>;
| ^^^
|
= note: the only supported types are integers, `bool`, and `char`
help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types
help: add `#[derive(ConstParamTy, PartialEq, Eq)]` to the struct
|
LL + #![feature(adt_const_params)]
|
help: add `#![feature(unsized_const_params)]` to the crate attributes to enable references to implement the `ConstParamTy` trait
|
LL + #![feature(unsized_const_params)]
LL - struct Bar(u8);
LL + #[derive(ConstParamTy, PartialEq, Eq)]
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The help message here is a bit weird, but feels like a pre-existing issue, can take a look at this after tihs PR.

@rust-cloud-vms rust-cloud-vms bot force-pushed the unstable_const_param branch from 8d88452 to 1f70531 Compare September 13, 2025 14:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants